package com.example.tasksmcpserver.service;

import com.example.tasksmcpserver.entity.Task;
import com.example.tasksmcpserver.repository.TaskRepository;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskService {
    private final TaskRepository taskRepository;

    @Autowired
    public TaskService(TaskRepository taskRepository) {
        this.taskRepository = taskRepository;
    }

    // 创建新任务
    @Tool
    public Task createTask(String name, String category) {
        Task task = new Task(name, category);
        return taskRepository.save(task);
    }

    @Tool
    // 根据名称查找任务
    public List<Task> findTasksByName(String name) {
        return taskRepository.findByNameContainingIgnoreCase(name);
    }

    @Tool
    // 根据类别查找任务
    public List<Task> findTasksByCategory(String category) {
        return taskRepository.findByCategoryIgnoreCase(category);
    }
} 